package com.bridgeQQ.client.control.userInfo
{
	import flash.net.SharedObject;
	import flash.net.registerClassAlias;
	
	import mx.collections.ArrayCollection;

	public class UserInfoSaver
	{
		private var lso:SharedObject;
		
		public function UserInfoSaver()
		{
			lso  = SharedObject.getLocal("userInfos", "/");
/*			lso.data.usersInfo = null;
			lso.flush();*/
		}
		
		public function save(user:String, password:String, autoLogin:Boolean):void
		{
			registerClassAlias("UserInfo", UserInfo);
			var temp:Array = lso.data.usersInfo as Array;
			if(!temp)
			{
				temp = new Array();
				lso.data.usersInfo = temp;
			}
			var found:Boolean;
			for(var i:int = temp.length - 1; i >= 0; i--)
			{
				var info:Object = temp[i];
				if(info.user == user)
				{
					info.autoLogin = autoLogin;
					info.password = password;
					found = true;
					temp.splice(i, 1);
					temp.unshift(info);
					break;
				}
			}
			if(!found)
			{
				temp.push(new UserInfo(user, password, autoLogin));
			}	
			lso.flush();
		}
		
		public function get savedInfo():ArrayCollection
		{
			registerClassAlias("UserInfo", UserInfo);
			var collection:ArrayCollection = new ArrayCollection();
			collection.source = lso.data.usersInfo as Array;
			return  collection;
		}
	}	
}

class UserInfo
{
	public var user:String;
	
	public var password:String;
	
	public var autoLogin:Boolean;
	
	function UserInfo(user:String, password:String, autoLogin:Boolean)
	{
		this.user = user;
		this.password = password;
		this.autoLogin = autoLogin;
	}
}